package ink.sunflowerk.util;

import javax.servlet.http.HttpSession;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author zhaokuii11@163.com
 * @create 2021-12-09 18:09
 * @Description
 */
public class ScheduleSessionUtil {
    /**
     * 设置5分钟后删除session中的验证码
     *
     * @param session  session
     * @param attrName 要删除session的名字
     * @param minute   分钟
     */
    public static void removeAttribute(final HttpSession session, final String attrName, int minute) {
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("删除了验证码");
                // 删除session中存的验证码
                session.removeAttribute(attrName);
                timer.cancel();
            }
        }, minute * 60 * 1000);
    }

}
